package com.cn.qgx428.orderingmeal.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cn.qgx428.orderingmeal.R;
import com.cn.qgx428.orderingmeal.myClass.Bankcard;
import com.cn.qgx428.orderingmeal.viewHolder.RViewHolder;

import java.util.List;

/**
 * Created by QinX on 2017/5/10.
 */

public class MineCardAdapter extends RBaseAdapter {

    private OnItemClickListener mOnclickListener;

    public interface OnItemClickListener{
        void onItemLongClick(View view, int position, String CardID);
    }

    public MineCardAdapter(Context context, List list, int itemLayoutId) {
        super(context, list, itemLayoutId);
    }

    @Override
    public void convert(final RViewHolder holder, Object item) {
        final LinearLayout cardItem = holder.getView(R.id.mine_cardItem);
        final TextView cardID = holder.getView(R.id.mine_itmeCardID);
        TextView cardName = holder.getView(R.id.mine_ItemCardName);

        Bankcard card = (Bankcard) item;

        final String preID = card.getCardID();
        String ID = hideID(preID);
        cardID.setText(ID);
        cardName.setText(card.getCardName());

        if (mOnclickListener != null){
            cardItem.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    int position = holder.getLayoutPosition();
                    mOnclickListener.onItemLongClick(cardItem,position,preID);
                    return false;
                }
            });
        }
    }

    private String hideID(String s) {
        String str = s.replace(" ","");
        str = "**** **** **** "+str.substring(str.length()-4,str.length());
        return str;
    }

    public void setOnClickItmeListener(OnItemClickListener listener){
        this.mOnclickListener = listener;
    }

}
